﻿package Interface 
{	
	import Core.Game;
	
	import Interface.MessagesClasses.ErrorMessage;
	import Interface.MessagesClasses.YesNoMessage;
	import Interface.MessagesClasses.InfoMessage;
	import Interface.MessagesClasses.TransferMessage;
	import Interface.MessagesClasses.TrackLoadingMessage;
	
	import flash.display.Sprite;	
	import flash.filters.GlowFilter;	
	import GameUtils.TrackData;
	
	public class PageMessages extends Sprite
	{
		private var FGame:Game;
		
		public function PageMessages():void
		{
			super();
		}
		
		private function Clear():void
		{
			while(numChildren > 1)
			{
				if(getChildAt(numChildren - 1) is TransferMessage)
					(getChildAt(numChildren - 1) as TransferMessage).Clear();
				removeChildAt(numChildren - 1);
			}
		}
		
		public function ShowError(AText:String):ErrorMessage
		{
			var vMessage:ErrorMessage = new ErrorMessage();
			vMessage.Text = AText;			
			AddMessage(Sprite(vMessage));
			return vMessage;
		}
		
		public function ShowInfo(AText:String, AHeaderText:String, AButtonText:String = 'OK'):InfoMessage
		{
			var vMessage:InfoMessage = new InfoMessage();
			vMessage.Text = AText;
			vMessage.Header = AHeaderText;
			vMessage.OKButton.Text = AButtonText;
			AddMessage(Sprite(vMessage));
			return vMessage;
		}
		
		public function ShowYesNo(AText:String, AHeaderText:String):YesNoMessage
		{
			var vMessage:YesNoMessage = new YesNoMessage();
			vMessage.Text = AText;
			vMessage.Header = AHeaderText;
			AddMessage(Sprite(vMessage));
			return vMessage;
		}		
		
		public function ShowTransfer():TransferMessage
		{
			var vMessage:TransferMessage = new TransferMessage(FGame);
			AddMessage(Sprite(vMessage));
			return vMessage;
		}
		
		public function ShowTrackLoading(ATrack:TrackData):TrackLoadingMessage
		{
			var vMessage:TrackLoadingMessage = new TrackLoadingMessage();
			vMessage.Track = ATrack;
			AddMessage(Sprite(vMessage));
			return vMessage;
		}
		
		private function AddMessage(AMessage:Sprite):void
		{
			Clear();
			visible = true;
			AMessage.x = 113.5;
			AMessage.y = 89;
			AMessage.filters = [new GlowFilter(0xFFFFFF, 0.8, 50, 50, 1, 2)];
			addChild(AMessage);
		}
		
		public function set GameCore(AGame:Game):void
		{
			FGame = AGame;
		}
	}
}
